package com.cskaoyan.main;

import com.mysql.jdbc.Driver;

import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.SQLException;
import java.sql.Statement;

/**
 * 创建日期: 2022/06/30 09:32
 *
 * @author ciggar
 */
public class UpdateDemo {

    public static void main(String[] args) throws SQLException {

        // 1.注册驱动
        DriverManager.registerDriver(new Driver());

        // 2. 获取连接
        Connection connection = DriverManager.getConnection("jdbc:mysql://localhost:3306/42th_rev?useSSL=false&characterEncoding=utf8",
                "root","123456");

        // 3. 获取statement对象
        Statement statement = connection.createStatement();

        // 4. 执行SQL语句
        int affectedRows = statement.executeUpdate("update student set name = '武大' where id = 3001");


        // 5. 解析结果集
        System.out.println(affectedRows);

        // 6. 关闭资源
        statement.close();
        connection.close();


    }
}
